<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Medium
  </div>
  <div>
   <h1 class="question_title">
    947. Online Election
   </h1>
   <p>
    In an election, the
    <code>
     i
    </code>
    -th&nbsp;vote was cast for
    <code>
     persons[i]
    </code>
    at time
    <code>
     times[i]
    </code>
    .
   </p>
   <p>
    Now, we would like to implement the following query function:
    <code>
     TopVotedCandidate.q(int t)
    </code>
    will return the number of the person that was leading the election at time
    <code>
     t
    </code>
    .&nbsp;&nbsp;
   </p>
   <p>
    Votes cast at time
    <code>
     t
    </code>
    will count towards our query.&nbsp; In the case of a tie, the most recent vote (among tied candidates) wins.
   </p>
   <p>
    &nbsp;
   </p>
   <div>
    <p>
     <strong>
      Example 1:
     </strong>
    </p>
    <pre>
<strong>Input: </strong><span id="example-input-1-1">["TopVotedCandidate","q","q","q","q","q","q"]</span>, <span id="example-input-1-2">[[[0,1,1,0,0,1,0],[0,5,10,15,20,25,30]],[3],[12],[25],[15],[24],[8]]</span>
<strong>Output: </strong><span id="example-output-1">[null,0,1,1,0,0,1]</span>
<strong>Explanation: </strong>
At time 3, the votes are [0], and 0 is leading.
At time 12, the votes are [0,1,1], and 1 is leading.
At time 25, the votes are [0,1,1,0,0,1], and 1 is leading (as ties go to the most recent vote.)
This continues for 3 more queries at time 15, 24, and 8.
</pre>
    <p>
     &nbsp;
    </p>
    <p>
     <strong>
      Note:
     </strong>
    </p>
    <ol>
     <li>
      <code>
       1 &lt;= persons.length = times.length &lt;= 5000
      </code>
     </li>
     <li>
      <code>
       0 &lt;= persons[i] &lt;= persons.length
      </code>
     </li>
     <li>
      <code>
       times
      </code>
      &nbsp;is a strictly increasing array with all elements in
      <code>
       [0, 10^9]
      </code>
      .
     </li>
     <li>
      <code>
       TopVotedCandidate.q
      </code>
      is called at most
      <code>
       10000
      </code>
      times per test case.
     </li>
     <li>
      <code>
       TopVotedCandidate.q(int t)
      </code>
      is always called with
      <code>
       t &gt;= times[0]
      </code>
      .
     </li>
    </ol>
   </div>
  </div>
  <div>
   <h1 class="question_title">
    947. 在线选举
   </h1>
   <p>
    在选举中，第&nbsp;
    <code>
     i
    </code>
    &nbsp;张票是在时间为&nbsp;
    <code>
     times[i]
    </code>
    &nbsp;时投给&nbsp;
    <code>
     persons[i]
    </code>
    &nbsp;的。
   </p>
   <p>
    现在，我们想要实现下面的查询函数：
    <code>
     TopVotedCandidate.q(int t)
    </code>
    将返回在&nbsp;
    <code>
     t
    </code>
    时刻主导选举的候选人的编号。
   </p>
   <p>
    在&nbsp;
    <code>
     t
    </code>
    时刻投出的选票也将被计入我们的查询之中。在平局的情况下，最近获得投票的候选人将会获胜。
   </p>
   <p>
    <strong>
     示例：
    </strong>
   </p>
   <pre><strong>输入：</strong>["TopVotedCandidate","q","q","q","q","q","q"], [[[0,1,1,0,0,1,0],[0,5,10,15,20,25,30]],[3],[12],[25],[15],[24],[8]]
<strong>输出：</strong>[null,0,1,1,0,0,1]
<strong>解释：</strong>
时间为 3，票数分布情况是 [0]，编号为 0 的候选人领先。
时间为 12，票数分布情况是 [0,1,1]，编号为 1 的候选人领先。
时间为 25，票数分布情况是 [0,1,1,0,0,1]，编号为 1 的候选人领先（因为最近的投票结果是平局）。
在时间 15、24 和 8 处继续执行 3 个查询。
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     提示：
    </strong>
   </p>
   <ol>
    <li>
     <code>
      1 &lt;= persons.length = times.length &lt;= 5000
     </code>
    </li>
    <li>
     <code>
      0 &lt;= persons[i] &lt;= persons.length
     </code>
    </li>
    <li>
     <code>
      times
     </code>
     &nbsp;是严格递增的数组，所有元素都在&nbsp;
     <code>
      [0, 10^9]
     </code>
     &nbsp;范围中。
    </li>
    <li>
     每个测试用例最多调用&nbsp;
     <code>
      10000
     </code>
     &nbsp;次&nbsp;
     <code>
      TopVotedCandidate.q
     </code>
     。
    </li>
    <li>
     <code>
      TopVotedCandidate.q(int t)
     </code>
     &nbsp;被调用时总是满足&nbsp;
     <code>
      t &gt;= times[0]
     </code>
     。
    </li>
   </ol>
  </div>
 </body>
</html>